package com.ruibang.glass.produce.controller.system;

import com.ruibang.glass.produce.domain.req.WorkshopReq;
import com.ruibang.glass.produce.entity.Workshop;
import com.ruibang.glass.produce.service.WorkshopService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-11-15  18:53
 * @Description: TODO：厂房控制器
 * @Version: 1.0
 */

@Api(tags = "厂房控制器")
@RestController
@RequestMapping("/api/glass/produce/workshop")
public class WorkshopController {

    @Autowired
    private WorkshopService workshopService;

    @GetMapping("/getWorkshopList")
    @ApiOperation(value = "获取厂房列表", response = ResultBody.class)
    public ResultBody getWorkshopList() {
        return ResultBody.success(workshopService.list());
    }

    @PostMapping("/queryWorkshop")
    @ApiOperation(value = "查询厂房信息", response = ResultBody.class)
    public ResultBody queryWorkshop(@RequestBody WorkshopReq workshopReq) {
        return ResultBody.success(workshopService.queryWorkshop(workshopReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody add(@RequestBody @Valid Workshop workshop) {
        workshopService.save(workshop);
        return ResultBody.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteById(@PathVariable String id) {
        workshopService.removeById(id);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "修改", response = ResultBody.class)
    public ResultBody edit(@RequestBody @Valid Workshop workshop) {
        workshopService.updateById(workshop);
        return ResultBody.success();
    }


}
